package com.atguigu.tingshu.user.config;


import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/***
 * 用户初始化账户消息队列配置,懒汉模式
 */
@Configuration
public class UserAndAccountRabbitConfig {
    /**
     * 创建交换机
     */
    @Bean("userAndAccountExchange")
    public Exchange userAndAccountExchange(){
        return ExchangeBuilder.directExchange("user_and_account_exchange").build();
    }
    /**
     * 创建队列
     */
    @Bean("userAndAccountQueue")
    public Queue userAndAccountQueue(){
        return QueueBuilder.durable("user_and_account_queue").build();
    }
    /**
     * 创建绑定
     */
    @Bean
    public Binding userAndAccountQueueBinding(@Qualifier("userAndAccountExchange")Exchange userAndAccountExchange,
                                              @Qualifier("userAndAccountQueue")Queue userAndAccountQueue){
        return BindingBuilder.bind(userAndAccountQueue).to(userAndAccountExchange).with("user.account").noargs();
    }
}
